package com.hyou.starter.autoconfigure.datasource;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.jdbc.datasource.AbstractDataSource;

/**
 * 多数据源支持的DataSource，自动装配时使用
 * 
 * @author FengChangshuo
 * @version 2.1.2 2018-09-26 15:30:19 初始创建
 */
public class MyDataSource extends AbstractDataSource {
    
    /**
     * 默认数据源标识
     */
    private String defaultDataSource;
    
    /**
     * 多个数据源配置集合。Key：数据源标识；Value：数据源对象
     */
    private Map<String, DataSource> dataSourceMap;
    
    public MyDataSource(Map<String, DataSource> dataSourceMap, String defaultDataSource) {
        this.dataSourceMap = dataSourceMap;
        this.defaultDataSource = defaultDataSource;
    }
    
    @Override
    public Connection getConnection() throws SQLException {
        throw new UnsupportedOperationException();
    }

    @Override
    public Connection getConnection(String username, String password) throws SQLException {
        throw new UnsupportedOperationException();
    }

    /**
     * @return the dataSourceMap
     */
    public Map<String, DataSource> getDataSourceMap() {
        return this.dataSourceMap;
    }

    /**
     * @param dataSourceMap the dataSourceMap to set
     */
    public void setDataSourceMap(Map<String, DataSource> dataSourceMap) {
        this.dataSourceMap = dataSourceMap;
    }

    /**
     * @return the defaultDataSource
     */
    public String getDefaultDataSource() {
        return this.defaultDataSource;
    }

    /**
     * @param defaultDataSource the defaultDataSource to set
     */
    public void setDefaultDataSource(String defaultDataSource) {
        this.defaultDataSource = defaultDataSource;
    }
    
}
